# RUN ANALYSES IN "IE analyses.do" to verify results!!!

# Figure A2
## Monarchism
fa2data.m <- data.frame(period=c(1982,1992,1997,2002,2007,2012,2017,2022),
                        effect=c(.1452275,-.0325961,-.0404695,-.0372834,-.0003443,.0433877,-.0208069,-.0571149),
                        se=c(.0076973,.0059107,.0046363,.0042645,.0052413,.0064399,.0052852,.006244))
fa2data.m$lci <- fa2data.m$effect-(1.96*fa2data.m$se)
fa2data.m$uci <- fa2data.m$effect+(1.96*fa2data.m$se)
fa2data.m$sig <- factor(ifelse(fa2data.m$lci<0 & fa2data.m$uci>0,"No","Yes"))
## Abolition
fa2data.a <- data.frame(period=c(1982,1992,1997,2002,2007,2012,2017,2022),
                        effect=c(-.0549729,.0153101,.0182559,.0049591,-.0105621,-.0257255,.0025958,.0501395),
                        se=c(.0073504,.0056443,.0044273,.0040723,.005005,.0061497,.005047,.0059626))
fa2data.a$lci <- fa2data.a$effect-(1.96*fa2data.a$se)
fa2data.a$uci <- fa2data.a$effect+(1.96*fa2data.a$se)
fa2data.a$sig <- factor(ifelse(fa2data.a$lci<0 & fa2data.a$uci>0,"No","Yes"))
## Joint Figure
fa2.m <- ggplot(fa2data.m,aes(x=period,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + ggtitle("Period, Monarchism") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.17) + scale_color_manual(values=c("Grey50","Black"),guide="none")
fa2.a <- ggplot(fa2data.a,aes(x=period,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("Period, Abolition") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.07, 0.08)
fa2 <- ggpubr::ggarrange(fa2.m,fa2.a,nrow=1)
# ggsave("Figure A2.png",fa2,device="png",width=6,height=4,units="in")

# Figure A3
## Monarchism
fa3data.m <- data.frame(age=c(15,20,25,30,35,40,45,50,55,60,65,70,75,80),
                       effect=c(-.0616411,-.06318,-.0687203,-.051282,-.0391463,-.0214693,-.02436,.0077736,.0215892,.0249158,.0487671,.0580482,.0795695,.0891357),
                       se=c(.0124686,.0092429,.0083292,.0072371,.0067277,.0063002,.0062599,.0062737,.0068107,.0075094,.0083484,.0091671,.010631,.0173095))
fa3data.m$lci <- fa3data.m$effect-(1.96*fa3data.m$se)
fa3data.m$uci <- fa3data.m$effect+(1.96*fa3data.m$se)
fa3data.m$sig <- factor(ifelse(fa3data.m$lci<0 & fa3data.m$uci>0,"No","Yes"))
## Abolition
fa3data.a <- data.frame(age=c(15,20,25,30,35,40,45,50,55,60,65,70,75,80),
                       effect=c(.0244898,.0207162,.0302187,.0156108,.0197607,.0121983,.0123696,-.0074183,-.0092897,.0073712,-.0216236,-.0267492,-.0331096,-.0445448),
                       se=c(.0119066,.0088263,.0079537,.0069109,.0064245,.0060163,.0059777,.0059909,.0065037,.0071709,.0079721,.0087539,.0101528,.0165293))
fa3data.a$lci <- fa3data.a$effect-(1.96*fa3data.a$se)
fa3data.a$uci <- fa3data.a$effect+(1.96*fa3data.a$se)
fa3data.a$sig <- factor(ifelse(fa3data.a$lci<0 & fa3data.a$uci>0,"No","Yes"))
## Joint Figure
fa3.m <- ggplot(fa3data.m,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("Age, Monarchism") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.22)
fa3.a <- ggplot(fa3data.a,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("Age, Abolition") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.13, 0.09)
fa3 <- ggpubr::ggarrange(fa3.m,fa3.a,nrow=1)
# ggsave("Figure A3.png",fa3,device="png",width=6,height=4,units="in")

# Figure A4
## Monarchism
fa4data.m <- data.frame(cohort=seq(1902,2002,by=5),
                       effect=c(.0460272,-.0157941,-.0003818,.0133483,-.0003142,.024377,.030431,.0368935,.0296907,.0128407,.0242802,.0120264,.0158956,.0107131,-.0064754,.0070078,-.0238389,-.0328696,-.06639,-.1143905,-.0030769),
                       se=c(.0947695,.0352829,.0228296,.0188472,.0166692,.0151042,.0137215,.0119606,.0107162,.0097218,.0090099,.007947,.0071685,.0067732,.0071855,.0073618,.0084471,.0096298,.0116366,.0132609,.0368524))
fa4data.m$lci <- fa4data.m$effect-(1.96*fa4data.m$se)
fa4data.m$uci <- fa4data.m$effect+(1.96*fa4data.m$se)
fa4data.m$sig <- ifelse(fa4data.m$lci<0 & fa4data.m$uci>0,"No","Yes")
## Abolition
fa4data.a <- data.frame(cohort=seq(1902,2002,by=5),
                       effect=c(.0199758,.0132748,.003749,-.0005704,.0137765,-.0141518,-.0070196,-.0156962,-.0146549,-.0049316,-.0195266,-.0068884,-.0185875,-.0062747,.0039357,-.006408,.00313,.0159591,.0533979,.0856796,-.0981688),
                       se=c(.090498,.0336926,.0218006,.0179977,.0159179,.0144234,.013103,.0114215,.0102332,.0092836,.0086038,.0075888,.0068454,.0064679,.0068616,.00703,.0080664,.0091957,.0111121,.0126632,.0351913))
fa4data.a$lci <- fa4data.a$effect-(1.96*fa4data.a$se)
fa4data.a$uci <- fa4data.a$effect+(1.96*fa4data.a$se)
fa4data.a$sig <- ifelse(fa4data.a$lci<0 & fa4data.a$uci>0,"No","Yes")
## Joint Figure
fa4.m <- ggplot(fa4data.m,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("Cohort, Monarchism") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.23, 0.42)
fa4.a <- ggplot(fa4data.a,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("Cohort, Abolition") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.32, 0.32)
fa4 <- ggpubr::ggarrange(fa4.m,fa4.a,nrow=1)
# ggsave("Figure A4.png",fa4,device="png",width=6,height=4,units="in")

# Figure, NHS Satisfaction
## Age
nhsdata.a <- data.frame(age=seq(15,80,by=5),
                        effect=c(-.0163147,-.0110099,-.036252,-.0313203,-.0168987,-.0186558,-.0174182,-.021245,-.0140327,.0059091,.0228052,.0245371,.0683918,.0617092),
                        se=c(.0129651,.0094027,.0085096,.0075151,.0071038,.0067364,.0065875,.0066243,.0072255,.0080381,.0087781,.0094091,.0109592,.0179362))
nhsdata.a$lci <- nhsdata.a$effect-(1.96*nhsdata.a$se)
nhsdata.a$uci <- nhsdata.a$effect+(1.96*nhsdata.a$se)
nhsdata.a$sig <- factor(ifelse(nhsdata.a$lci<0 & nhsdata.a$uci>0,"No","Yes"))
p.nhs.a <- ggplot(nhsdata.a,aes(x=age,y=effect,colour=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + ggtitle("Age") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.16, 0.24) + scale_color_manual(values=c("Grey50","Black"),guide="none")
## Period
nhsdata.p <- data.frame(period=c(1982,1992,1997,2002,2007,2012,2017,2022),
                        effect=c(.0628454,-.0490241,-.0249373,-.0203477,.0538726,.1006835,.0151682,-.1382606),
                        se=c(.0075672,.0058697,.0046548,.0051375,.0088094,.0063763,.0052811,.006371))
nhsdata.p$lci <- nhsdata.p$effect-(1.96*nhsdata.p$se)
nhsdata.p$uci <- nhsdata.p$effect+(1.96*nhsdata.p$se)
nhsdata.p$sig <- factor(ifelse(nhsdata.p$lci<0 & nhsdata.p$uci>0,"No","Yes"))
p.nhs.p <- ggplot(nhsdata.p,aes(x=period,y=effect)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + ggtitle("Period") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.16, 0.24)
## Cohort
nhsdata.c <- data.frame(cohort=seq(1902,2002,by=5),
                        effect=c(.050434,.0134741,.0453427,.0164253,-.00245,-.0149026,-.0041038,-.0336958,-.032053,-.0462137,-.0452493,-.0499392,-.0382647,-.0234222,-.0249094,-.0045238,.0123462,.0035789,.0079254,.0045701,.1656308),
                        se=c(.092209,.0344494,.0222337,.0185313,.0166372,.0153849,.0139174,.0120188,.0107742,.0098081,.00917,.0081821,.0074631,.007109,.0076809,.0079776,.0093019,.0101754,.0116338,.0136251,.0361231))
nhsdata.c$lci <- nhsdata.c$effect-(1.96*nhsdata.c$se)
nhsdata.c$uci <- nhsdata.c$effect+(1.96*nhsdata.c$se)
nhsdata.c$sig <- factor(ifelse(nhsdata.c$lci<0 & nhsdata.c$uci>0,"No","Yes"))
p.nhs.c <- ggplot(nhsdata.c,aes(x=cohort,y=effect,colour=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + ggtitle("Cohort") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.16, 0.24) + scale_color_manual(values=c("Grey50","Black"),guide="none")
## Together
p.nhs <- ggpubr::ggarrange(p.nhs.a,p.nhs.p,p.nhs.c,nrow=2,ncol=2)
## ggsave("NHS IE.png",p.nhs,device="png",width=6,height=4,units="in")

# Figure, Government Trust
## Age
govdata.a <- data.frame(age=seq(20,80,by=5),
                        effect=c(.0197973,-.0117187,.0003248,-.0013389,-.0040341,-.0118385,-.0023022,-.0228011,-.0071776,-.0005008,-.0055415,.0144345,.032697),
                        se=c(.0099892,.0086976,.0077646,.0073793,.006981,.0069591,.0070556,.0075397,.0080781,.0087912,.0097381,.0111691,.0197159))
govdata.a$lci <- govdata.a$effect-(1.96*govdata.a$se)
govdata.a$uci <- govdata.a$effect+(1.96*govdata.a$se)
govdata.a$sig <- factor(ifelse(govdata.a$lci<0 & govdata.a$uci>0,"No","Yes"))
p.gov.a <- ggplot(govdata.a,aes(x=age,y=effect,colour=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + ggtitle("Age") + theme(plot.title = element_text(hjust = 0.5)) + scale_color_manual(values=c("Grey50","Black"),guide="none") + ylim(-0.21, 0.09)
## Period
govdata.p <- data.frame(period=seq(1992,2022,by=5),
                        effect=c(.0343724,.020477,.0210803,.0269297,-.0202228,-.0068264,-.0758102),
                        se=c(.0059304,.0046807,.0042598,.0054104,.0070433,.0075645,.0068313))
govdata.p$lci <- govdata.p$effect-(1.96*govdata.p$se)
govdata.p$uci <- govdata.p$effect+(1.96*govdata.p$se)
govdata.p$sig <- factor(ifelse(govdata.p$lci<0 & govdata.p$uci>0,"No","Yes"))
p.gov.p <- ggplot(govdata.p,aes(x=period,y=effect,colour=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + ggtitle("Period") + theme(plot.title = element_text(hjust = 0.5)) + scale_color_manual(values=c("Grey50","Black"),guide="none") + ylim(-0.21, 0.09)
## Cohort
govdata.c <- data.frame(cohort=seq(1912,2002,by=5),
                        effect=c(-.0623051,.030602,.0248338,.0009863,.0113059,.0070849,.0050649,-.0031304,.0078933,-.0033689,-.0062705,.0171568,.0007855,.019254,.0124865,.0071075,-.0141751,-.0400696,-.0152417),
                        se=c(.0743545,.0245317,.0182691,.0157258,.0143108,.0131684,.0116158,.0105156,.0096602,.009086,.0080086,.0073647,.0068375,.007474,.008519,.0116532,.0134036,.0164284,.0200902))
govdata.c$lci <- govdata.c$effect-(1.96*govdata.c$se)
govdata.c$uci <- govdata.c$effect+(1.96*govdata.c$se)
govdata.c$sig <- factor(ifelse(govdata.c$lci<0 & govdata.c$uci>0,"No","Yes"))
p.gov.c <- ggplot(govdata.c,aes(x=cohort,y=effect,colour=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + ggtitle("Cohort") + theme(plot.title = element_text(hjust = 0.5)) + scale_color_manual(values=c("Grey50","Black"),guide="none") + ylim(-0.21, 0.09)
## Together
p.gov <- ggpubr::ggarrange(p.gov.a,p.gov.p,p.gov.c,nrow=2,ncol=2)
## ggsave("Gov IE.png",p.gov,device="png",width=6,height=4,units="in")

# Figure, MP Trust
## Age
mpsdata.a <- data.frame(age=seq(20,80,by=5),
                        effect=c(.0167674,.0030195,-.0061435,-.010145,-.002595,-.0042257,-.0086485,.0045384,-.0092948,-.0084686,-.0039318,-.0045312,.0343588),
                        se=c(.0093654,.0081275,.0071873,.0068258,.0065207,.0065993,.0067579,.007124,.0074451,.0081409,.0089956,.0103859,.0179401))
mpsdata.a$lci <- mpsdata.a$effect-(1.96*mpsdata.a$se)
mpsdata.a$uci <- mpsdata.a$effect+(1.96*mpsdata.a$se)
mpsdata.a$sig <- factor(ifelse(mpsdata.a$lci<0 & mpsdata.a$uci>0,"No","Yes"))
p.mps.a <- ggplot(mpsdata.a,aes(x=age,y=effect,colour=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + ggtitle("Age") + theme(plot.title = element_text(hjust = 0.5)) + scale_color_manual(values=c("Grey50","Black"),guide="none") + ylim(-0.18, 0.08)
## Period
mpsdata.p <- data.frame(period=c(1992,1997,2002,2007,2012,2022),
                        effect=c(.0120147,.0221442,-.0019563,.0132565,-.0123586,-.0331006),
                        se=c(.0049962,.0038922,.0035919,.0046881,.0062083,.0057305))
mpsdata.p$lci <- mpsdata.p$effect-(1.96*mpsdata.p$se)
mpsdata.p$uci <- mpsdata.p$effect+(1.96*mpsdata.p$se)
mpsdata.p$sig <- factor(ifelse(mpsdata.p$lci<0 & mpsdata.p$uci>0,"No","Yes"))
p.mps.p <- ggplot(mpsdata.p,aes(x=period,y=effect,colour=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + ggtitle("Period") + theme(plot.title = element_text(hjust = 0.5)) + scale_color_manual(values=c("Grey50","Black"),guide="none") + ylim(-0.18, 0.08)
## Cohort
mpsdata.c <- data.frame(cohort=seq(1912,1997,by=5),
                        effect=c(-.0455673,.0321731,.0267439,.0052164,-.0146019,.0004892,-.0076784,-.0252581,-.0034337,.00563145,.001388,.004738,-.0049605,.0170318,.0089581,.0098287,-.0272988,.0165998),
                        se=c(.0638847,.0220367,.0162823,.0138962,.0126413,.0112301,.0104405,.0093914,.0088408,.0081525,.0072181,.0065859,.0062141,.0067684,.0081154,.0111911,.0142355,.0180154))
mpsdata.c$lci <- mpsdata.c$effect-(1.96*mpsdata.c$se)
mpsdata.c$uci <- mpsdata.c$effect+(1.96*mpsdata.c$se)
mpsdata.c$sig <- factor(ifelse(mpsdata.c$lci<0 & mpsdata.c$uci>0,"No","Yes"))
p.mps.c <- ggplot(mpsdata.c,aes(x=cohort,y=effect,colour=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + ggtitle("Cohort") + theme(plot.title = element_text(hjust = 0.5))  + scale_color_manual(values=c("Grey50","Black"),guide="none") + ylim(-0.18, 0.08)
## Together
p.mps <- ggpubr::ggarrange(p.mps.a,p.mps.p,p.mps.c,nrow=2,ncol=2)
## ggsave("MPs IE.png",p.mps,device="png",width=6,height=4,units="in")

# Controlling for Demographics
## Age
controldata.m.a <- data.frame(age=seq(15,80,by=5),
                        effect=c(-.0646066,-.0602678,-.067268,-.0546233,-.0429554,-.0237778,-.0199036,.0134694,.0213627,.0231361,.0472264,.0571176,.0778431,.0932472),
                        se=c(.0138106,.0091542,.0083315,.0074049,.0071417,.0068157,.006887,.0069993,.0075144,.00813,.0089309,.0095971,.0111358,.0193629))
controldata.m.a$lci <- controldata.m.a$effect-(1.96*controldata.m.a$se)
controldata.m.a$uci <- controldata.m.a$effect+(1.96*controldata.m.a$se)
controldata.m.a$sig <- factor(ifelse(controldata.m.a$lci<0 & controldata.m.a$uci>0,"No","Yes"))
controldata.a.a <- data.frame(age=seq(15,80,by=5),
                             effect=c(.0304543,.0170246,.0294211,.0173592,.023846,.0132609,.0099242,-.0149819,-.0070433,.0079883,-.0242965,-.0266287,-.0338328,-.0424953),
                             se=c(.0133936,.0088778,.00808,.0071813,.0069261,.0066099,.0066791,.006788,.0072875,.0078846,.0086612,.0093073,.0107995,.0187783))
controldata.a.a$lci <- controldata.a.a$effect-(1.96*controldata.a.a$se)
controldata.a.a$uci <- controldata.a.a$effect+(1.96*controldata.a.a$se)
controldata.a.a$sig <- factor(ifelse(controldata.a.a$lci<0 & controldata.a.a$uci>0,"No","Yes"))
p.control.m.a <- ggplot(controldata.m.a,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("Demogs") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.22)
p.control.a.a <- ggplot(controldata.a.a,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("Demogs") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.13, 0.09)
## Period
controldata.m.p <- data.frame(period=c(seq(1992,2022,by=5)),
                        effect=c(-.0086516,-.0162516,-.0139545,.0245646,.0655423,-.0005804,-.0506687),
                        se=c(.005819,.0048186,.0044511,.0055119,.0065386,.0052221,.0060436))
controldata.m.p$lci <- controldata.m.p$effect-(1.96*controldata.m.p$se)
controldata.m.p$uci <- controldata.m.p$effect+(1.96*controldata.m.p$se)
controldata.m.p$sig <- factor(ifelse(controldata.m.p$lci<0 & controldata.m.p$uci>0,"No","Yes"))
controldata.a.p <- data.frame(period=c(seq(1992,2022,by=5)),
                              effect=c(.0055862,.0075995,-.0056269,-.0223078,-.0369154,-.0023833,.0540477),
                              se=c(.0056433,.0046731,.0043167,.0053455,.0063411,.0050644,.0058611))
controldata.a.p$lci <- controldata.a.p$effect-(1.96*controldata.a.p$se)
controldata.a.p$uci <- controldata.a.p$effect+(1.96*controldata.a.p$se)
controldata.a.p$sig <- factor(ifelse(controldata.a.p$lci<0 & controldata.a.p$uci>0,"No","Yes"))
p.control.m.p <- ggplot(controldata.m.p,aes(x=period,y=effect)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + ggtitle("Demogs") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.17)
p.control.a.p <- ggplot(controldata.a.p,aes(x=period,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("Demogs") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.07, 0.08)
## Cohort
controldata.m.c <- data.frame(cohort=seq(1912,2007,by=5),
                        effect=c(.0154244,-.0051869,.0190706,-.014946,.0211653,.0309452,.0328814,.0295119,.0113299,.0248189,.018637,.0239371,.0182513,.0025811,.0177005,-.0129838,-.0323845,-.059067,-.1224655,-.0192201),
                        se=c(.0776878,.0261061,.0191989,.0164676,.0149132,.0136603,.011832,.0108035,.0100618,.0095461,.0085457,.0079437,.0075703,.0079181,.0080803,.0092117,.0106028,.012829,.0156379,.0454728))
controldata.m.c$lci <- controldata.m.c$effect-(1.96*controldata.m.c$se)
controldata.m.c$uci <- controldata.m.c$effect+(1.96*controldata.m.c$se)
controldata.m.c$sig <- factor(ifelse(controldata.m.c$lci<0 & controldata.m.c$uci>0,"No","Yes"))
controldata.a.c <- data.frame(cohort=seq(1912,2007,by=5),
                              effect=c(-.006994,.0102813,.0012398,.0313439,-.0072735,-.0021433,-.0089517,-.0072812,.0021367,-.0193437,-.005247,-.0181428,-.0086026,.0032009,-.0096904,-.0067029,.0182065,.041428,.0835438,-.0910077),
                              se=c(.0753421,.0253178,.0186192,.0159703,.0144629,.0132479,.0114748,.0104773,.0097579,.0092579,.0082877,.0077039,.0073417,.007679,.0078363,.0089336,.0102826,.0124416,.0151657,.0440998))
controldata.a.c$lci <- controldata.a.c$effect-(1.96*controldata.a.c$se)
controldata.a.c$uci <- controldata.a.c$effect+(1.96*controldata.a.c$se)
controldata.a.c$sig <- factor(ifelse(controldata.a.c$lci<0 & controldata.a.c$uci>0,"No","Yes"))
p.control.m.c <- ggplot(controldata.m.c,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("Demogs") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.23, 0.42)
p.control.a.c <- ggplot(controldata.a.c,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("Demogs") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.32, 0.32)

# Controlling for Demographics + Ideology
## Age
controldata1.m.a <- data.frame(age=seq(15,80,by=5),
                            effect=c(-.0500286,-.054416,-.0576539,-.0449911,-.0504223,-.0198642,-.0217047,.0097896,.0216279,.0222275,.0470401,.0523431,.051248,.0908302),
                            se=c(.0162583,.0113315,.0100334,.0086732,.0079835,.007374,.0072965,.0074298,.0079676,.0090238,.0101072,.0112498,.013205,.0219433))
controldata1.m.a$lci <- controldata1.m.a$effect-(1.96*controldata1.m.a$se)
controldata1.m.a$uci <- controldata1.m.a$effect+(1.96*controldata1.m.a$se)
controldata1.m.a$sig <- factor(ifelse(controldata1.m.a$lci<0 & controldata1.m.a$uci>0,"No","Yes"))
controldata1.a.a <- data.frame(age=seq(15,80,by=5),
                               effect=c(.0254345,.0051525,.0227529,.006901,.0295532,.0129561,.065655,-.0087091,-.0068358,.0087805,-.0224807,-.0280044,-.0140367,-.0480295),
                               se=c(.0162662,.011337,.0100383,.0086774,.0079874,.0073776,.0073001,.0074334,.0079715,.0090282,.0101121,.0112552,.0132114,.0219539))
controldata1.a.a$lci <- controldata1.a.a$effect-(1.96*controldata1.a.a$se)
controldata1.a.a$uci <- controldata1.a.a$effect+(1.96*controldata1.a.a$se)
controldata1.a.a$sig <- factor(ifelse(controldata1.a.a$lci<0 & controldata1.a.a$uci>0,"No","Yes"))
p.control1.m.a <- ggplot(controldata1.m.a,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("D + Ideology") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.22)
p.control1.a.a <- ggplot(controldata1.a.a,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("D + Ideology") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.13, 0.09)
## Period
controldata1.m.p <- data.frame(period=seq(1992,2022,by=5),
                            effect=c(-.0121119,-.0289595,-.0357255,-.0083977,.0600716,.0266404,-.0015174),
                            se=c(.0074148,.0054496,.0047648,.0056218,.006822,.0057532,.0074411))
controldata1.m.p$lci <- controldata1.m.p$effect-(1.96*controldata1.m.p$se)
controldata1.m.p$uci <- controldata1.m.p$effect+(1.96*controldata1.m.p$se)
controldata1.m.p$sig <- factor(ifelse(controldata1.m.p$lci<0 & controldata1.m.p$uci>0,"No","Yes"))
controldata1.a.p <- data.frame(period=seq(1992,2022,by=5),
                               effect=c(.0048763,.0118866,.0097657,.002219,-.0325702,-.0189627,.0227853),
                               se=c(.0074184,.0054523,.0047671,.0056245,.0068254,.005756,.0074447))
controldata1.a.p$lci <- controldata1.a.p$effect-(1.96*controldata1.a.p$se)
controldata1.a.p$uci <- controldata1.a.p$effect+(1.96*controldata1.a.p$se)
controldata1.a.p$sig <- factor(ifelse(controldata1.a.p$lci<0 & controldata1.a.p$uci>0,"No","Yes"))
p.control1.m.p <- ggplot(controldata1.m.p,aes(x=period,y=effect)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + ggtitle("D + Ideology") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.17)
p.control1.a.p <- ggplot(controldata1.a.p,aes(x=period,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("D + Ideology") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.07, 0.08)
## Cohort
controldata1.m.c <- data.frame(cohort=seq(1912,2007,by=5),
                            effect=c(.0400289,-.0056442,.0132744,-.0178646,.0048504,.0123688,.0240027,.0088709,-.0011997,.0200021,.0072672,.0071344,-.0074994,-.0077016,.0021306,-.0155788,-.0189156,-.0499669,-.0706144,.0550549),
                            se=c(.1116233,.0339353,.0245507,.021068,.018931,.0171896,.0149325,.0134759,.0122651,.0112463,.009916,.0088887,.0082601,.0083382,.008386,.0096825,.0113795,.0137935,.0171761,.0435318))
controldata1.m.c$lci <- controldata1.m.c$effect-(1.96*controldata1.m.c$se)
controldata1.m.c$uci <- controldata1.m.c$effect+(1.96*controldata1.m.c$se)
controldata1.m.c$sig <- factor(ifelse(controldata1.m.c$lci<0 & controldata1.m.c$uci>0,"No","Yes"))
controldata1.a.c <- data.frame(cohort=seq(1912,2007,by=5),
                               effect=c(-.035969,.0126235,.0102187,.0363764,.0026938,.0139948,-.0041793,.0053407,.0082461,-.018334,.0049543,-.0080885,.012113,.0068787,.00000616,-.0002901,.0179558,.0357191,.036278,-.1365382),
                               se=c(.1116776,.0339518,.0245626,.0210782,.0189402,.017198,.0149397,.0134824,.0122711,.0112518,.0099208,.0088931,.0082642,.0083422,.00839,.0096872,.011385,.0138002,.0171844,.043553))
controldata1.a.c$lci <- controldata1.a.c$effect-(1.96*controldata1.a.c$se)
controldata1.a.c$uci <- controldata1.a.c$effect+(1.96*controldata1.a.c$se)
controldata1.a.c$sig <- factor(ifelse(controldata1.a.c$lci<0 & controldata1.a.c$uci>0,"No","Yes"))
p.control1.m.c <- ggplot(controldata1.m.c,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("D + Ideology") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.23, 0.42)
p.control1.a.c <- ggplot(controldata1.a.c,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("D + Ideology") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.32, 0.32)

# Controlling for Demographics + Trust
## Age
controldata2.m.a <- data.frame(age=seq(20,80,by=5),
                               effect=c(-.0637903,-.0663862,-.0664462,-.0459582,-.0187732,-.0279023,-.0146004,.0291041,.0242306,.0269914,.0469221,.056226,.1203728),
                               se=c(.0126448,.0109116,.0097332,.0093031,.008792,.0087492,.0089412,.0096034,.0102934,.011161,.0124565,.0142449,.0250635))
controldata2.m.a$lci <- controldata2.m.a$effect-(1.96*controldata2.m.a$se)
controldata2.m.a$uci <- controldata2.m.a$effect+(1.96*controldata2.m.a$se)
controldata2.m.a$sig <- factor(ifelse(controldata2.m.a$lci<0 & controldata2.m.a$uci>0,"No","Yes"))
controldata2.a.a <- data.frame(age=seq(20,80,by=5),
                               effect=c(.0276799,.0259476,.0207042,.0181962,.0052662,.0155372,-.0086183,-.0251858,.0019062,-.0141952,-.0206055,-.0104092,-.0362234),
                               se=c(.0121747,.0105059,.0093714,.0089572,.0084651,.008424,.0086088,.0092464,.0099107,.0107461,.0119934,.0137153,.0241317))
controldata2.a.a$lci <- controldata2.a.a$effect-(1.96*controldata2.a.a$se)
controldata2.a.a$uci <- controldata2.a.a$effect+(1.96*controldata2.a.a$se)
controldata2.a.a$sig <- factor(ifelse(controldata2.a.a$lci<0 & controldata2.a.a$uci>0,"No","Yes"))
p.control2.m.a <- ggplot(controldata2.m.a,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("D + Trust") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.22)
p.control2.a.a <- ggplot(controldata2.a.a,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("D + Trust") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.13, 0.09)
## Period
controldata2.m.p <- data.frame(period=seq(1992,2022,by=5),
                               effect=c(-.0230649,-.0381183,-.0177431,.0245379,.0762041,.0530128,-.0748285),
                               se=c(.007464,.0059149,.0053903,.0070831,.0092066,.0094783,.0087519))
controldata2.m.p$lci <- controldata2.m.p$effect-(1.96*controldata2.m.p$se)
controldata2.m.p$uci <- controldata2.m.p$effect+(1.96*controldata2.m.p$se)
controldata2.m.p$sig <- factor(ifelse(controldata2.m.p$lci<0 & controldata2.m.p$uci>0,"No","Yes"))
controldata2.a.p <- data.frame(period=seq(1992,2022,by=5),
                               effect=c(.0201482,.0200928,-.0031645,-.0193807,-.0455866,-.0312576,.0591485),
                               se=c(.0071865,.005695,.0051899,.0068198,.0088643,.0091259,.0084265))
controldata2.a.p$lci <- controldata2.a.p$effect-(1.96*controldata2.a.p$se)
controldata2.a.p$uci <- controldata2.a.p$effect+(1.96*controldata2.a.p$se)
controldata2.a.p$sig <- factor(ifelse(controldata2.a.p$lci<0 & controldata2.a.p$uci>0,"No","Yes"))
p.control2.m.p <- ggplot(controldata2.m.p,aes(x=period,y=effect)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + ggtitle("D + Trust") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.17)
p.control2.a.p <- ggplot(controldata2.a.p,aes(x=period,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("D + Trust") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.07, 0.08)
## Cohort
controldata2.m.c <- data.frame(cohort=seq(1912,2002,by=5),
                               effect=c(.0235052,-.015326,.0356109,-.012192,.0260238,.0299804,.0305572,.0164777,.0200469,.0216422,.0193268,.0031353,.0193558,-.0046326,.0101753,-.0251227,-.0355525,-.0652881,-.0977237),
                               se=c(.0913881,.0308089,.002288,.0196281,.0179333,.0165474,.0145022,.0131838,.012139,.0114491,.0100824,.0092591,.0086929,.0095409,.0109228,.0149426,.0173681,.020587,.0280212))
controldata2.m.c$lci <- controldata2.m.c$effect-(1.96*controldata2.m.c$se)
controldata2.m.c$uci <- controldata2.m.c$effect+(1.96*controldata2.m.c$se)
controldata2.m.c$sig <- factor(ifelse(controldata2.m.c$lci<0 & controldata2.m.c$uci>0,"No","Yes"))
controldata2.a.c <- data.frame(cohort=seq(1912,2002,by=5),
                               effect=c(-.0034695,.0018262,-.0176544,.0286281,-.0193639,.0004539,-.0094277,.0064284,-.0042848,-.0206778,-.0067191,-.0030093,-.0083423,.0025839,-.0122322,.0069149,.0151402,.0387662,.0044392),
                               se=c(.0879904,.0296635,.0220294,.0188984,.0172666,.0159323,.0139631,.0126937,.0116877,.0110235,.0097075,.0089149,.0083697,.0091862,.0105167,.0143871,.0167224,.0198216,.0269795))
controldata2.a.c$lci <- controldata2.a.c$effect-(1.96*controldata2.a.c$se)
controldata2.a.c$uci <- controldata2.a.c$effect+(1.96*controldata2.a.c$se)
controldata2.a.c$sig <- factor(ifelse(controldata2.a.c$lci<0 & controldata2.a.c$uci>0,"No","Yes"))
p.control2.m.c <- ggplot(controldata2.m.c,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("D + Trust") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.23, 0.42)
p.control2.a.c <- ggplot(controldata2.a.c,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("D + Trust") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.32, 0.32)

# Controlling for Demographics + Trust + Ideology
## Age
controldata3.m.a <- data.frame(age=seq(20,80,by=5),
                               effect=c(-.0528862,-.0620142,-.0564306,-.0635291,-.0221821,-.0388976,-.0266806,.0206104,.024289,.0375443,.050606,.0389734,.1505973),
                               se=c(.0186041,.0158632,.0134767,.0118831,.0104941,.0098278,.0098473,.0105371,.0121133,.0137598,.0162197,.0188462,.0309367))
controldata3.m.a$lci <- controldata3.m.a$effect-(1.96*controldata3.m.a$se)
controldata3.m.a$uci <- controldata3.m.a$effect+(1.96*controldata3.m.a$se)
controldata3.m.a$sig <- factor(ifelse(controldata3.m.a$lci<0 & controldata3.m.a$uci>0,"No","Yes"))
controldata3.a.a <- data.frame(age=seq(20,80,by=5),
                               effect=c(.0092514,.0200314,.0090945,.0301579,.012551,.0283928,.005841,-.0190101,.0020117,-.0163503,-.0241127,.011555,-.0671178),
                               se=c(.0182897,.015595,.0132489,.0116822,.0103168,.0096617,.0096809,.010359,.0119085,.0135273,.0159456,.0185276,.0304138))
controldata3.a.a$lci <- controldata3.a.a$effect-(1.96*controldata3.a.a$se)
controldata3.a.a$uci <- controldata3.a.a$effect+(1.96*controldata3.a.a$se)
controldata3.a.a$sig <- factor(ifelse(controldata3.a.a$lci<0 & controldata3.a.a$uci>0,"No","Yes"))
p.control3.m.a <- ggplot(controldata3.m.a,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("All") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.22)
p.control3.a.a <- ggplot(controldata3.a.a,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("All") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.13, 0.09)
## Period
controldata3.m.p <- data.frame(period=seq(1992,2022,by=5),
                               effect=c(-.0125474,-.0391667,-.0325851,-.0000603,.0657617,.0687063,-.0501085),
                               se=c(.0113414,.0075672,.0061354,.007346,.0097694,.0110177,.011935))
controldata3.m.p$lci <- controldata3.m.p$effect-(1.96*controldata3.m.p$se)
controldata3.m.p$uci <- controldata3.m.p$effect+(1.96*controldata3.m.p$se)
controldata3.m.p$sig <- factor(ifelse(controldata3.m.p$lci<0 & controldata3.m.p$uci>0,"No","Yes"))
controldata3.a.p <- data.frame(period=seq(1992,2022,by=5),
                               effect=c(.016826,.0180675,.0087994,-.0040024,-.039416,-.0351932,.0349187),
                               se=c(.0111497,.0074393,.0060317,.0072218,.0096043,.0108314,.0117333))
controldata3.a.p$lci <- controldata3.a.p$effect-(1.96*controldata3.a.p$se)
controldata3.a.p$uci <- controldata3.a.p$effect+(1.96*controldata3.a.p$se)
controldata3.a.p$sig <- factor(ifelse(controldata3.a.p$lci<0 & controldata3.a.p$uci>0,"No","Yes"))
p.control3.m.p <- ggplot(controldata3.m.p,aes(x=period,y=effect)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + ggtitle("All") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.17)
p.control3.a.p <- ggplot(controldata3.a.p,aes(x=period,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("All") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.07, 0.08)
## Cohort
controldata3.m.c <- data.frame(cohort=seq(1912,2002,by=5),
                               effect=c(.0921335,-.0561545,.0351543,-.0145695,.0067799,.0073426,.0173624,.0062152,.0143798,.0305956,.0209962,-.0041709,.0007348,-.0061822,-.0049736,-.0274157,-.0218943,-.040131,-.0562026),
                               se=c(.1635817,.0458544,.0348,.0301336,.0272388,.0246549,.0215367,.019075,.0170081,.0151361,.0128716,.0110941,.0099163,.010249,.0120938,.0170638,.020638,.0249766,.0329004))
controldata3.m.c$lci <- controldata3.m.c$effect-(1.96*controldata3.m.c$se)
controldata3.m.c$uci <- controldata3.m.c$effect+(1.96*controldata3.m.c$se)
controldata3.m.c$sig <- factor(ifelse(controldata3.m.c$lci<0 & controldata3.m.c$uci>0,"No","Yes"))
controldata3.a.c <- data.frame(cohort=seq(1912,2002,by=5),
                               effect=c(-.0031765,.0193525,-.0257158,.0198313,-.0148482,.0155716,-.0054033,.0090835,-.0072483,-.0323958,-.0085204,-.002044,.0060447,.000957,-.0082412,.0172609,.0203676,.0078244,-.0086998),
                               se=c(.1608169,.0450794,.0342118,.0296242,.0267784,.0242382,.0211727,.0187525,.0167207,.0148803,.0126541,.0109065,.0097487,.0100758,.0118894,.0167753,.0202891,.0245545,.0323443))
controldata3.a.c$lci <- controldata3.a.c$effect-(1.96*controldata3.a.c$se)
controldata3.a.c$uci <- controldata3.a.c$effect+(1.96*controldata3.a.c$se)
controldata3.a.c$sig <- factor(ifelse(controldata3.a.c$lci<0 & controldata3.a.c$uci>0,"No","Yes"))
p.control3.m.c <- ggplot(controldata3.m.c,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("All") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.23, 0.42)
p.control3.a.c <- ggplot(controldata3.a.c,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("All") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.32, 0.32)

# Figures Controlling for Things
## Age
fa3.m1 <- ggplot(fa3data.m,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("None") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.22)
fa3.a1 <- ggplot(fa3data.a,aes(x=age,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Age") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("None") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.13, 0.09)
p.m.age <- ggpubr::ggarrange(fa3.m1,p.control.m.a,p.control1.m.a,p.control2.m.a,p.control3.m.a,nrow=2,ncol=3)
p.a.age <- ggpubr::ggarrange(fa3.a1,p.control.a.a,p.control1.a.a,p.control2.a.a,p.control3.a.a,nrow=2,ncol=3)
#ggsave("Age Monarchism IE.png",p.m.age,device="png",width=6,height=4,units="in")
#ggsave("Age Abolition IE.png",p.a.age,device="png",width=6,height=4,units="in")
## Period
fa2.m1 <- ggplot(fa2data.m,aes(x=period,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + ggtitle("None") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.10, 0.17) + scale_color_manual(values=c("Grey50","Black"),guide="none")
fa2.a1 <- ggplot(fa2data.a,aes(x=period,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Period") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("None") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.07, 0.08)
p.m.period <- ggpubr::ggarrange(fa2.m1,p.control.m.p,p.control1.m.p,p.control2.m.p,p.control3.m.p,nrow=2,ncol=3)
p.a.period <- ggpubr::ggarrange(fa2.a1,p.control.a.p,p.control1.a.p,p.control2.a.p,p.control3.a.p,nrow=2,ncol=3)
#ggsave("Period Monarchism IE.png",p.m.period,device="png",width=6,height=4,units="in")
#ggsave("Period Abolition IE.png",p.a.period,device="png",width=6,height=4,units="in")
## Cohort
fa4.m1 <- ggplot(fa4data.m,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("None") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.23, 0.42)
fa4.a1 <- ggplot(fa4data.a,aes(x=cohort,y=effect,color=sig)) + geom_point() + theme_classic() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0) + geom_hline(yintercept=0,linetype="dashed",color="red") +xlab("Cohort") + ylab("Difference from Grand Mean") + scale_color_manual(values=c("Grey50","Black"),guide="none") + ggtitle("None") + theme(plot.title = element_text(hjust = 0.5)) + ylim(-0.32, 0.32)
p.m.cohort <- ggpubr::ggarrange(fa4.m1,p.control.m.c,p.control1.m.c,p.control2.m.c,p.control3.m.c,nrow=2,ncol=3)
p.a.cohort <- ggpubr::ggarrange(fa4.a1,p.control.a.c,p.control1.a.c,p.control2.a.c,p.control3.a.c,nrow=2,ncol=3)
#ggsave("Cohort Monarchism IE.png",p.m.cohort,device="png",width=6,height=4,units="in")
#ggsave("Cohort Abolition IE.png",p.a.cohort,device="png",width=6,height=4,units="in")
